using System;
using DevExpress.Xpo.DB;
using Common;
using DevExpress.Xpo.DB.Helpers;

namespace Client
{
    /// <summary>
    /// Proxy for ICachedDataStore
    /// </summary>
    public class CachedDataStoreClientProxy : ICachedDataStore
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="CachedDataStoreClientProxy"/> class.
        /// </summary>
        /// <param name="wrappedDataStoreContract">The wrapped data store contract.</param>
        public CachedDataStoreClientProxy(ICachedDataStoreContract wrappedDataStoreContract)
        {
            this.wrappedDataStoreContract = wrappedDataStoreContract;
        }

        ICachedDataStoreContract wrappedDataStoreContract;
        /// <summary>
        /// Gets the wrapped data store contract.
        /// </summary>
        /// <value>The wrapped data store contract.</value>
        public ICachedDataStoreContract WrappedDataStoreContract
        {
            get
            {
                return wrappedDataStoreContract;
            }
        }

        #region IDataStore Members

        /// <summary>
        /// Returns which operations are performed when a data store is accessed for the first time.
        /// </summary>
        /// <value>
        /// An <see cref="T:DevExpress.Xpo.DB.AutoCreateOption"/> value that specifies which operations are performed when a data store is accessed for the first time.
        /// </value>
        AutoCreateOption IDataStore.AutoCreateOption
        {
            get { return wrappedDataStoreContract.GetAutoCreateOption(); }
        }

        /// <summary>
        /// Updates data in a data store using the specified modification statements.
        /// </summary>
        /// <param name="dmlStatements">An array of data modification statements.</param>
        /// <returns>The result of the data modifications.</returns>
        ModificationResult IDataStore.ModifyData(params ModificationStatement[] dmlStatements)
        {
            return wrappedDataStoreContract.ModifyData(dmlStatements);
        }

        /// <summary>
        /// Fetches data from a data store using the specified query statements.
        /// </summary>
        /// <param name="selects">An array of statements to obtain data from the data store.</param>
        /// <returns>Data retrieved from the data store.</returns>
        SelectedData IDataStore.SelectData(params SelectStatement[] selects)
        {
            return wrappedDataStoreContract.SelectData(selects);
        }

        /// <summary>
        /// Updates the storage schema according to the specified class descriptions.
        /// </summary>
        /// <param name="dontCreateIfFirstTableNotExist"><b>true</b> if the schema should not be created if the table that corresponds to the first item in the <i>tables</i> array doesn't exist in the data store.</param>
        /// <param name="tables">An array of tables whose structure should be saved in the data store.</param>
        /// <returns>
        /// An <see cref="T:DevExpress.Xpo.DB.UpdateSchemaResult"/> value that specifies the result of the update operation.
        /// </returns>
        UpdateSchemaResult IDataStore.UpdateSchema(bool dontCreateIfFirstTableNotExist, params DBTable[] tables)
        {
            return wrappedDataStoreContract.UpdateSchema(dontCreateIfFirstTableNotExist, tables);
        }

        #endregion

        #region ICacheToCacheCommunicationCore Members

        /// <summary>
        /// Updates data in a data store using the specified modification statements.
        /// </summary>
        /// <param name="cookie">The Data Cache Cookie.</param>
        /// <param name="dmlStatements">An array of data modification statements.</param>
        /// <returns>The result of the data modifications.</returns>
        DataCacheModificationResult ICacheToCacheCommunicationCore.ModifyData(DataCacheCookie cookie, ModificationStatement[] dmlStatements)
        {
            return wrappedDataStoreContract.ModifyDataCached(cookie, dmlStatements);
        }

        /// <summary>
        /// Notifies the dirty tables.
        /// </summary>
        /// <param name="cookie">The Data Cache Cookie.</param>
        /// <param name="dirtyTablesNames">The dirty table names.</param>
        /// <returns></returns>
        DataCacheResult ICacheToCacheCommunicationCore.NotifyDirtyTables(DataCacheCookie cookie, params string[] dirtyTablesNames)
        {
            return wrappedDataStoreContract.NotifyDirtyTables(cookie, dirtyTablesNames);
        }

        /// <summary>
        /// Processes The Data Cache Cookie.
        /// </summary>
        /// <param name="cookie">The Data Cache Cookie.</param>
        /// <returns></returns>
        DataCacheResult ICacheToCacheCommunicationCore.ProcessCookie(DataCacheCookie cookie)
        {
            return wrappedDataStoreContract.ProcessCookie(cookie);
        }

        /// <summary>
        /// Fetches data from a data store using the specified query statements.
        /// </summary>
        /// <param name="cookie">The Data Cache Cookie.</param>
        /// <param name="selects">An array of statements to obtain data from the data store.</param>
        /// <returns>Data retrieved from the data store.</returns>
        DataCacheSelectDataResult ICacheToCacheCommunicationCore.SelectData(DataCacheCookie cookie, SelectStatement[] selects)
        {
            return wrappedDataStoreContract.SelectDataCached(cookie, selects);
        }

        /// <summary>
        /// Updates the storage schema according to the specified class descriptions.
        /// </summary>
        /// <param name="cookie">The Data Cache Cookie.</param>
        /// <param name="tables">An array of tables whose structure should be saved in the data store.</param>
        /// <param name="dontCreateIfFirstTableNotExist"><b>true</b> if the schema should not be created if the table that corresponds to the first item in the <i>tables</i> array doesn't exist in the data store.</param>
        /// <returns>
        /// An <see cref="T:DevExpress.Xpo.DB.UpdateSchemaResult"/> value that specifies the result of the update operation.
        /// </returns>
        DataCacheUpdateSchemaResult ICacheToCacheCommunicationCore.UpdateSchema(DataCacheCookie cookie, DBTable[] tables, bool dontCreateIfFirstTableNotExist)
        {
            return wrappedDataStoreContract.UpdateSchemaCached(cookie, tables, dontCreateIfFirstTableNotExist);
        }

        #endregion
    }
}
